<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=9"/>
<meta name="generator" content="Doxygen 1.8.11"/>
<title>Cheetah Software: PositionVelocityEstimator.cpp Source File</title>
<link href="../../tabs.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="../../jquery.js"></script>
<script type="text/javascript" src="../../dynsections.js"></script>
<link href="../../navtree.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="../../resize.js"></script>
<script type="text/javascript" src="../../navtreedata.js"></script>
<script type="text/javascript" src="../../navtree.js"></script>
<script type="text/javascript">
  $(document).ready(initResizable);
  $(window).load(resizeHeight);
</script>
<link href="../../search/search.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="../../search/searchdata.js"></script>
<script type="text/javascript" src="../../search/search.js"></script>
<script type="text/javascript">
  $(document).ready(function() { init_search(); });
</script>
<link href="../../doxygen.css" rel="stylesheet" type="text/css" />
</head>
<body>
<div id="top"><!-- do not remove this div, it is closed by doxygen! -->
<div id="titlearea">
<table cellspacing="0" cellpadding="0">
 <tbody>
 <tr style="height: 56px;">
  <td id="projectalign" style="padding-left: 0.5em;">
   <div id="projectname">Cheetah Software
   &#160;<span id="projectnumber">1.0</span>
   </div>
  </td>
 </tr>
 </tbody>
</table>
</div>
<!-- end header part -->
<!-- Generated by Doxygen 1.8.11 -->
<script type="text/javascript">
var searchBox = new SearchBox("searchBox", "../../search",false,'Search');
</script>
  <div id="navrow1" class="tabs">
    <ul class="tablist">
      <li><a href="../../index.html"><span>Main&#160;Page</span></a></li>
      <li><a href="../../namespaces.html"><span>Namespaces</span></a></li>
      <li><a href="../../annotated.html"><span>Classes</span></a></li>
      <li class="current"><a href="../../files.html"><span>Files</span></a></li>
      <li>
        <div id="MSearchBox" class="MSearchBoxInactive">
        <span class="left">
          <img id="MSearchSelect" src="../../search/mag_sel.png"
               onmouseover="return searchBox.OnSearchSelectShow()"
               onmouseout="return searchBox.OnSearchSelectHide()"
               alt=""/>
          <input type="text" id="MSearchField" value="Search" accesskey="S"
               onfocus="searchBox.OnSearchFieldFocus(true)" 
               onblur="searchBox.OnSearchFieldFocus(false)" 
               onkeyup="searchBox.OnSearchFieldChange(event)"/>
          </span><span class="right">
            <a id="MSearchClose" href="javascript:searchBox.CloseResultsWindow()"><img id="MSearchCloseImg" border="0" src="../../search/close.png" alt=""/></a>
          </span>
        </div>
      </li>
    </ul>
  </div>
  <div id="navrow2" class="tabs2">
    <ul class="tablist">
      <li><a href="../../files.html"><span>File&#160;List</span></a></li>
      <li><a href="../../globals.html"><span>File&#160;Members</span></a></li>
    </ul>
  </div>
</div><!-- top -->
<div id="side-nav" class="ui-resizable side-nav-resizable">
  <div id="nav-tree">
    <div id="nav-tree-contents">
      <div id="nav-sync" class="sync"></div>
    </div>
  </div>
  <div id="splitbar" style="-moz-user-select:none;" 
       class="ui-resizable-handle">
  </div>
</div>
<script type="text/javascript">
$(document).ready(function(){initNavTree('d6/d39/_position_velocity_estimator_8cpp_source.html','../../');});
</script>
<div id="doc-content">
<!-- window showing the filter options -->
<div id="MSearchSelectWindow"
     onmouseover="return searchBox.OnSearchSelectShow()"
     onmouseout="return searchBox.OnSearchSelectHide()"
     onkeydown="return searchBox.OnSearchSelectKey(event)">
</div>

<!-- iframe showing the search results (closed by default) -->
<div id="MSearchResultsWindow">
<iframe src="javascript:void(0)" frameborder="0" 
        name="MSearchResults" id="MSearchResults">
</iframe>
</div>

<div class="header">
  <div class="headertitle">
<div class="title">PositionVelocityEstimator.cpp</div>  </div>
</div><!--header-->
<div class="contents">
<a href="../../d6/d39/_position_velocity_estimator_8cpp.html">Go to the documentation of this file.</a><div class="fragment"><div class="line"><a name="l00001"></a><span class="lineno">    1</span>&#160;<span class="preprocessor">#include &quot;<a class="code" href="../../df/ddd/_position_velocity_estimator_8h.html">Controllers/PositionVelocityEstimator.h</a>&quot;</span></div><div class="line"><a name="l00002"></a><span class="lineno">    2</span>&#160;</div><div class="line"><a name="l00003"></a><span class="lineno">    3</span>&#160;<span class="keyword">template</span> &lt;<span class="keyword">typename</span> T&gt;</div><div class="line"><a name="l00004"></a><span class="lineno"><a class="line" href="../../d1/d83/class_linear_k_f_position_velocity_estimator.html#aa6cde24b1d9be72b01cfae1534e7580f">    4</a></span>&#160;<span class="keywordtype">void</span> <a class="code" href="../../d1/d83/class_linear_k_f_position_velocity_estimator.html#aa6cde24b1d9be72b01cfae1534e7580f">LinearKFPositionVelocityEstimator&lt;T&gt;::setup</a>() {</div><div class="line"><a name="l00005"></a><span class="lineno">    5</span>&#160;  printf(<span class="stringliteral">&quot;beans 0x%lx\n&quot;</span>, (uint64_t)<span class="keyword">this</span>);</div><div class="line"><a name="l00006"></a><span class="lineno">    6</span>&#160;  printf(<span class="stringliteral">&quot;beans2 0x%lx\n&quot;</span>, (uint64_t) &amp; (this-&gt;_stateEstimatorData));</div><div class="line"><a name="l00007"></a><span class="lineno">    7</span>&#160;  printf(<span class="stringliteral">&quot;beans3 0x%lx\n&quot;</span>, (uint64_t)(this-&gt;_stateEstimatorData.parameters));</div><div class="line"><a name="l00008"></a><span class="lineno">    8</span>&#160;  printf(<span class="stringliteral">&quot;beans4 0x%lx\n&quot;</span>,</div><div class="line"><a name="l00009"></a><span class="lineno">    9</span>&#160;         (uint64_t) &amp; (this-&gt;_stateEstimatorData.parameters-&gt;controller_dt));</div><div class="line"><a name="l00010"></a><span class="lineno">   10</span>&#160;  T dt = this-&gt;_stateEstimatorData.parameters-&gt;controller_dt;</div><div class="line"><a name="l00011"></a><span class="lineno">   11</span>&#160;  printf(<span class="stringliteral">&quot;Initialize LinearKF State Estimator with dt = %.3f\n&quot;</span>, dt);</div><div class="line"><a name="l00012"></a><span class="lineno">   12</span>&#160;  _xhat.setZero();</div><div class="line"><a name="l00013"></a><span class="lineno">   13</span>&#160;  _ps.setZero();</div><div class="line"><a name="l00014"></a><span class="lineno">   14</span>&#160;  _vs.setZero();</div><div class="line"><a name="l00015"></a><span class="lineno">   15</span>&#160;  _A.setZero();</div><div class="line"><a name="l00016"></a><span class="lineno">   16</span>&#160;  _A.block(0, 0, 3, 3) = Eigen::Matrix&lt;T, 3, 3&gt;::Identity();</div><div class="line"><a name="l00017"></a><span class="lineno">   17</span>&#160;  _A.block(0, 3, 3, 3) = dt * Eigen::Matrix&lt;T, 3, 3&gt;::Identity();</div><div class="line"><a name="l00018"></a><span class="lineno">   18</span>&#160;  _A.block(3, 3, 3, 3) = Eigen::Matrix&lt;T, 3, 3&gt;::Identity();</div><div class="line"><a name="l00019"></a><span class="lineno">   19</span>&#160;  _A.block(6, 6, 12, 12) = Eigen::Matrix&lt;T, 12, 12&gt;::Identity();</div><div class="line"><a name="l00020"></a><span class="lineno">   20</span>&#160;  _B.setZero();</div><div class="line"><a name="l00021"></a><span class="lineno">   21</span>&#160;  _B.block(3, 0, 3, 3) = dt * Eigen::Matrix&lt;T, 3, 3&gt;::Identity();</div><div class="line"><a name="l00022"></a><span class="lineno">   22</span>&#160;  Eigen::Matrix&lt;T, Eigen::Dynamic, Eigen::Dynamic&gt; C1(3, 6);</div><div class="line"><a name="l00023"></a><span class="lineno">   23</span>&#160;  C1 &lt;&lt; Eigen::Matrix&lt;T, 3, 3&gt;::Identity(), Eigen::Matrix&lt;T, 3, 3&gt;::Zero();</div><div class="line"><a name="l00024"></a><span class="lineno">   24</span>&#160;  Eigen::Matrix&lt;T, Eigen::Dynamic, Eigen::Dynamic&gt; C2(3, 6);</div><div class="line"><a name="l00025"></a><span class="lineno">   25</span>&#160;  C2 &lt;&lt; Eigen::Matrix&lt;T, 3, 3&gt;::Zero(), Eigen::Matrix&lt;T, 3, 3&gt;::Identity();</div><div class="line"><a name="l00026"></a><span class="lineno">   26</span>&#160;  _C.setZero();</div><div class="line"><a name="l00027"></a><span class="lineno">   27</span>&#160;  _C.block(0, 0, 3, 6) = C1;</div><div class="line"><a name="l00028"></a><span class="lineno">   28</span>&#160;  _C.block(3, 0, 3, 6) = C1;</div><div class="line"><a name="l00029"></a><span class="lineno">   29</span>&#160;  _C.block(6, 0, 3, 6) = C1;</div><div class="line"><a name="l00030"></a><span class="lineno">   30</span>&#160;  _C.block(9, 0, 3, 6) = C1;</div><div class="line"><a name="l00031"></a><span class="lineno">   31</span>&#160;  _C.block(0, 6, 12, 12) = T(-1) * Eigen::Matrix&lt;T, 12, 12&gt;::Identity();</div><div class="line"><a name="l00032"></a><span class="lineno">   32</span>&#160;  _C.block(12, 0, 3, 6) = C2;</div><div class="line"><a name="l00033"></a><span class="lineno">   33</span>&#160;  _C.block(15, 0, 3, 6) = C2;</div><div class="line"><a name="l00034"></a><span class="lineno">   34</span>&#160;  _C.block(18, 0, 3, 6) = C2;</div><div class="line"><a name="l00035"></a><span class="lineno">   35</span>&#160;  _C.block(21, 0, 3, 6) = C2;</div><div class="line"><a name="l00036"></a><span class="lineno">   36</span>&#160;  _C(27, 17) = T(1);</div><div class="line"><a name="l00037"></a><span class="lineno">   37</span>&#160;  _C(26, 14) = T(1);</div><div class="line"><a name="l00038"></a><span class="lineno">   38</span>&#160;  _C(25, 11) = T(1);</div><div class="line"><a name="l00039"></a><span class="lineno">   39</span>&#160;  _C(24, 8) = T(1);</div><div class="line"><a name="l00040"></a><span class="lineno">   40</span>&#160;  _P.setIdentity();</div><div class="line"><a name="l00041"></a><span class="lineno">   41</span>&#160;  _P = T(100) * _P;</div><div class="line"><a name="l00042"></a><span class="lineno">   42</span>&#160;  _Q0.setIdentity();</div><div class="line"><a name="l00043"></a><span class="lineno">   43</span>&#160;  _Q0.block(0, 0, 3, 3) = (dt / 20.f) * Eigen::Matrix&lt;T, 3, 3&gt;::Identity();</div><div class="line"><a name="l00044"></a><span class="lineno">   44</span>&#160;  _Q0.block(3, 3, 3, 3) =</div><div class="line"><a name="l00045"></a><span class="lineno">   45</span>&#160;      (dt * 9.8f / 20.f) * Eigen::Matrix&lt;T, 3, 3&gt;::Identity();</div><div class="line"><a name="l00046"></a><span class="lineno">   46</span>&#160;  _Q0.block(6, 6, 12, 12) = dt * Eigen::Matrix&lt;T, 12, 12&gt;::Identity();</div><div class="line"><a name="l00047"></a><span class="lineno">   47</span>&#160;  _R0.setIdentity();</div><div class="line"><a name="l00048"></a><span class="lineno">   48</span>&#160;}</div><div class="line"><a name="l00049"></a><span class="lineno">   49</span>&#160;</div><div class="line"><a name="l00050"></a><span class="lineno">   50</span>&#160;<span class="keyword">template</span> &lt;<span class="keyword">typename</span> T&gt;</div><div class="line"><a name="l00051"></a><span class="lineno"><a class="line" href="../../d1/d83/class_linear_k_f_position_velocity_estimator.html#a6fcb890559e303e4c8e13cef4dd6c4d9">   51</a></span>&#160;<a class="code" href="../../d1/d83/class_linear_k_f_position_velocity_estimator.html#a6fcb890559e303e4c8e13cef4dd6c4d9">LinearKFPositionVelocityEstimator&lt;T&gt;::LinearKFPositionVelocityEstimator</a>() {}</div><div class="line"><a name="l00052"></a><span class="lineno">   52</span>&#160;</div><div class="line"><a name="l00053"></a><span class="lineno">   53</span>&#160;<span class="keyword">template</span> &lt;<span class="keyword">typename</span> T&gt;</div><div class="line"><a name="l00054"></a><span class="lineno"><a class="line" href="../../d1/d83/class_linear_k_f_position_velocity_estimator.html#a5a71e5a86165a39dda4c6ad81304299a">   54</a></span>&#160;<span class="keywordtype">void</span> <a class="code" href="../../d1/d83/class_linear_k_f_position_velocity_estimator.html#a5a71e5a86165a39dda4c6ad81304299a">LinearKFPositionVelocityEstimator&lt;T&gt;::run</a>() {</div><div class="line"><a name="l00055"></a><span class="lineno">   55</span>&#160;  T process_noise_pimu =</div><div class="line"><a name="l00056"></a><span class="lineno">   56</span>&#160;      this-&gt;_stateEstimatorData.parameters-&gt;imu_process_noise_position;</div><div class="line"><a name="l00057"></a><span class="lineno">   57</span>&#160;  T process_noise_vimu =</div><div class="line"><a name="l00058"></a><span class="lineno">   58</span>&#160;      this-&gt;_stateEstimatorData.parameters-&gt;imu_process_noise_velocity;</div><div class="line"><a name="l00059"></a><span class="lineno">   59</span>&#160;  T process_noise_pfoot =</div><div class="line"><a name="l00060"></a><span class="lineno">   60</span>&#160;      this-&gt;_stateEstimatorData.parameters-&gt;foot_process_noise_position;</div><div class="line"><a name="l00061"></a><span class="lineno">   61</span>&#160;  T sensor_noise_pimu_rel_foot =</div><div class="line"><a name="l00062"></a><span class="lineno">   62</span>&#160;      this-&gt;_stateEstimatorData.parameters-&gt;foot_sensor_noise_position;</div><div class="line"><a name="l00063"></a><span class="lineno">   63</span>&#160;  T sensor_noise_vimu_rel_foot =</div><div class="line"><a name="l00064"></a><span class="lineno">   64</span>&#160;      this-&gt;_stateEstimatorData.parameters-&gt;foot_sensor_noise_velocity;</div><div class="line"><a name="l00065"></a><span class="lineno">   65</span>&#160;  T sensor_noise_zfoot =</div><div class="line"><a name="l00066"></a><span class="lineno">   66</span>&#160;      this-&gt;_stateEstimatorData.parameters-&gt;foot_height_sensor_noise;</div><div class="line"><a name="l00067"></a><span class="lineno">   67</span>&#160;</div><div class="line"><a name="l00068"></a><span class="lineno">   68</span>&#160;  Eigen::Matrix&lt;T, 18, 18&gt; Q = Eigen::Matrix&lt;T, 18, 18&gt;::Identity();</div><div class="line"><a name="l00069"></a><span class="lineno">   69</span>&#160;  Q.block(0, 0, 3, 3) = _Q0.block(0, 0, 3, 3) * process_noise_pimu;</div><div class="line"><a name="l00070"></a><span class="lineno">   70</span>&#160;  Q.block(3, 3, 3, 3) = _Q0.block(3, 3, 3, 3) * process_noise_vimu;</div><div class="line"><a name="l00071"></a><span class="lineno">   71</span>&#160;  Q.block(6, 6, 12, 12) = _Q0.block(6, 6, 12, 12) * process_noise_pfoot;</div><div class="line"><a name="l00072"></a><span class="lineno">   72</span>&#160;</div><div class="line"><a name="l00073"></a><span class="lineno">   73</span>&#160;  Eigen::Matrix&lt;T, 28, 28&gt; R = Eigen::Matrix&lt;T, 28, 28&gt;::Identity();</div><div class="line"><a name="l00074"></a><span class="lineno">   74</span>&#160;  R.block(0, 0, 12, 12) = _R0.block(0, 0, 12, 12) * sensor_noise_pimu_rel_foot;</div><div class="line"><a name="l00075"></a><span class="lineno">   75</span>&#160;  R.block(12, 12, 12, 12) =</div><div class="line"><a name="l00076"></a><span class="lineno">   76</span>&#160;      _R0.block(12, 12, 12, 12) * sensor_noise_vimu_rel_foot;</div><div class="line"><a name="l00077"></a><span class="lineno">   77</span>&#160;  R.block(24, 24, 4, 4) = _R0.block(24, 24, 4, 4) * sensor_noise_zfoot;</div><div class="line"><a name="l00078"></a><span class="lineno">   78</span>&#160;</div><div class="line"><a name="l00079"></a><span class="lineno">   79</span>&#160;  <span class="keywordtype">int</span> qindex = 0;</div><div class="line"><a name="l00080"></a><span class="lineno">   80</span>&#160;  <span class="keywordtype">int</span> rindex1 = 0;</div><div class="line"><a name="l00081"></a><span class="lineno">   81</span>&#160;  <span class="keywordtype">int</span> rindex2 = 0;</div><div class="line"><a name="l00082"></a><span class="lineno">   82</span>&#160;  <span class="keywordtype">int</span> rindex3 = 0;</div><div class="line"><a name="l00083"></a><span class="lineno">   83</span>&#160;</div><div class="line"><a name="l00084"></a><span class="lineno">   84</span>&#160;  <a class="code" href="../../d9/d8e/cpp_types_8h.html#a6f07728c866b15ff0676a9b2ebfd2ba6">Vec3&lt;T&gt;</a> g(0, 0, T(-9.81));</div><div class="line"><a name="l00085"></a><span class="lineno">   85</span>&#160;  <a class="code" href="../../d9/d8e/cpp_types_8h.html#aa8cb424e643d476ea485238dad7c3e18">Mat3&lt;T&gt;</a> Rbod = this-&gt;_stateEstimatorData.result-&gt;rBody.transpose();</div><div class="line"><a name="l00086"></a><span class="lineno">   86</span>&#160;  <a class="code" href="../../d9/d8e/cpp_types_8h.html#a6f07728c866b15ff0676a9b2ebfd2ba6">Vec3&lt;T&gt;</a> a = this-&gt;_stateEstimatorData.result-&gt;aWorld +</div><div class="line"><a name="l00087"></a><span class="lineno">   87</span>&#160;              g;  <span class="comment">// in old code, Rbod * se_acc + g</span></div><div class="line"><a name="l00088"></a><span class="lineno">   88</span>&#160;  <span class="comment">// std::cout &lt;&lt; &quot;A WORLD\n&quot; &lt;&lt; a &lt;&lt; &quot;\n&quot;;</span></div><div class="line"><a name="l00089"></a><span class="lineno">   89</span>&#160;  <a class="code" href="../../d9/d8e/cpp_types_8h.html#a738072d0d6a7a632be68f6261501826b">Vec4&lt;T&gt;</a> pzs = <a class="code" href="../../d9/d8e/cpp_types_8h.html#a738072d0d6a7a632be68f6261501826b">Vec4&lt;T&gt;::Zero</a>();</div><div class="line"><a name="l00090"></a><span class="lineno">   90</span>&#160;  <a class="code" href="../../d9/d8e/cpp_types_8h.html#a738072d0d6a7a632be68f6261501826b">Vec4&lt;T&gt;</a> trusts = <a class="code" href="../../d9/d8e/cpp_types_8h.html#a738072d0d6a7a632be68f6261501826b">Vec4&lt;T&gt;::Zero</a>();</div><div class="line"><a name="l00091"></a><span class="lineno">   91</span>&#160;  <a class="code" href="../../d9/d8e/cpp_types_8h.html#a6f07728c866b15ff0676a9b2ebfd2ba6">Vec3&lt;T&gt;</a> p0, v0;</div><div class="line"><a name="l00092"></a><span class="lineno">   92</span>&#160;  p0 &lt;&lt; _xhat[0], _xhat[1], _xhat[2];</div><div class="line"><a name="l00093"></a><span class="lineno">   93</span>&#160;  v0 &lt;&lt; _xhat[3], _xhat[4], _xhat[5];</div><div class="line"><a name="l00094"></a><span class="lineno">   94</span>&#160;</div><div class="line"><a name="l00095"></a><span class="lineno">   95</span>&#160;  <span class="keywordflow">for</span> (<span class="keywordtype">int</span> i = 0; i &lt; 4; i++) {</div><div class="line"><a name="l00096"></a><span class="lineno">   96</span>&#160;    <span class="keywordtype">int</span> i1 = 3 * i;</div><div class="line"><a name="l00097"></a><span class="lineno">   97</span>&#160;    <a class="code" href="../../dc/d66/class_quadruped.html">Quadruped&lt;T&gt;</a>&amp; quadruped =</div><div class="line"><a name="l00098"></a><span class="lineno">   98</span>&#160;        *(this-&gt;_stateEstimatorData.legControllerData-&gt;quadruped);</div><div class="line"><a name="l00099"></a><span class="lineno">   99</span>&#160;    <a class="code" href="../../d9/d8e/cpp_types_8h.html#a6f07728c866b15ff0676a9b2ebfd2ba6">Vec3&lt;T&gt;</a> ph = quadruped.<a class="code" href="../../dc/d66/class_quadruped.html#a594bd8c71ee8f6c388501b4c463d26b2">getHipLocation</a>(i);  <span class="comment">// hip positions relative to CoM</span></div><div class="line"><a name="l00100"></a><span class="lineno">  100</span>&#160;    <a class="code" href="../../d9/d8e/cpp_types_8h.html#a6f07728c866b15ff0676a9b2ebfd2ba6">Vec3&lt;T&gt;</a> p_rel = ph + this-&gt;_stateEstimatorData.legControllerData[i]</div><div class="line"><a name="l00101"></a><span class="lineno">  101</span>&#160;                             .p;  <span class="comment">// hw_i-&gt;leg_controller-&gt;leg_datas[i].p; //</span></div><div class="line"><a name="l00102"></a><span class="lineno">  102</span>&#160;    <a class="code" href="../../d9/d8e/cpp_types_8h.html#a6f07728c866b15ff0676a9b2ebfd2ba6">Vec3&lt;T&gt;</a> dp_rel = this-&gt;_stateEstimatorData.legControllerData[i]</div><div class="line"><a name="l00103"></a><span class="lineno">  103</span>&#160;                         .v;  <span class="comment">// hw_i-&gt;leg_controller-&gt;leg_datas[i].v;</span></div><div class="line"><a name="l00104"></a><span class="lineno">  104</span>&#160;    <a class="code" href="../../d9/d8e/cpp_types_8h.html#a6f07728c866b15ff0676a9b2ebfd2ba6">Vec3&lt;T&gt;</a> p_f = Rbod * p_rel;</div><div class="line"><a name="l00105"></a><span class="lineno">  105</span>&#160;    <a class="code" href="../../d9/d8e/cpp_types_8h.html#a6f07728c866b15ff0676a9b2ebfd2ba6">Vec3&lt;T&gt;</a> dp_f =</div><div class="line"><a name="l00106"></a><span class="lineno">  106</span>&#160;        Rbod *</div><div class="line"><a name="l00107"></a><span class="lineno">  107</span>&#160;        (this-&gt;_stateEstimatorData.result-&gt;omegaBody.cross(p_rel) + dp_rel);</div><div class="line"><a name="l00108"></a><span class="lineno">  108</span>&#160;</div><div class="line"><a name="l00109"></a><span class="lineno">  109</span>&#160;    qindex = 6 + i1;</div><div class="line"><a name="l00110"></a><span class="lineno">  110</span>&#160;    rindex1 = i1;</div><div class="line"><a name="l00111"></a><span class="lineno">  111</span>&#160;    rindex2 = 12 + i1;</div><div class="line"><a name="l00112"></a><span class="lineno">  112</span>&#160;    rindex3 = 24 + i;</div><div class="line"><a name="l00113"></a><span class="lineno">  113</span>&#160;</div><div class="line"><a name="l00114"></a><span class="lineno">  114</span>&#160;    T trust = T(1);</div><div class="line"><a name="l00115"></a><span class="lineno">  115</span>&#160;    T phase = fmin(this-&gt;_stateEstimatorData.result-&gt;contactEstimate(i), T(1));</div><div class="line"><a name="l00116"></a><span class="lineno">  116</span>&#160;    T trust_window = T(0.2);</div><div class="line"><a name="l00117"></a><span class="lineno">  117</span>&#160;</div><div class="line"><a name="l00118"></a><span class="lineno">  118</span>&#160;    <span class="keywordflow">if</span> (phase &lt; trust_window) {</div><div class="line"><a name="l00119"></a><span class="lineno">  119</span>&#160;      trust = phase / trust_window;</div><div class="line"><a name="l00120"></a><span class="lineno">  120</span>&#160;    } <span class="keywordflow">else</span> <span class="keywordflow">if</span> (phase &gt; (T(1) - trust_window)) {</div><div class="line"><a name="l00121"></a><span class="lineno">  121</span>&#160;      trust = (T(1) - phase) / trust_window;</div><div class="line"><a name="l00122"></a><span class="lineno">  122</span>&#160;    }</div><div class="line"><a name="l00123"></a><span class="lineno">  123</span>&#160;</div><div class="line"><a name="l00124"></a><span class="lineno">  124</span>&#160;    <span class="comment">// printf(&quot;Trust %d: %.3f\n&quot;, i, trust);</span></div><div class="line"><a name="l00125"></a><span class="lineno">  125</span>&#160;    Q.block(qindex, qindex, 3, 3) =</div><div class="line"><a name="l00126"></a><span class="lineno">  126</span>&#160;        (T(1) + (T(1) - trust) * T(100)) * Q.block(qindex, qindex, 3, 3);</div><div class="line"><a name="l00127"></a><span class="lineno">  127</span>&#160;    R.block(rindex1, rindex1, 3, 3) = 1 * R.block(rindex1, rindex1, 3, 3);</div><div class="line"><a name="l00128"></a><span class="lineno">  128</span>&#160;    R.block(rindex2, rindex2, 3, 3) =</div><div class="line"><a name="l00129"></a><span class="lineno">  129</span>&#160;        (T(1) + (T(1) - trust) * 100.0<a class="code" href="../../dc/dd7/test__casadi_8cpp.html#ae20d7fba59865a21504b65cdb44cbfe5">f</a>) * R.block(rindex2, rindex2, 3, 3);</div><div class="line"><a name="l00130"></a><span class="lineno">  130</span>&#160;    R(rindex3, rindex3) =</div><div class="line"><a name="l00131"></a><span class="lineno">  131</span>&#160;        (T(1) + (T(1) - trust) * T(100)) * R(rindex3, rindex3);</div><div class="line"><a name="l00132"></a><span class="lineno">  132</span>&#160;</div><div class="line"><a name="l00133"></a><span class="lineno">  133</span>&#160;    trusts(i) = trust;</div><div class="line"><a name="l00134"></a><span class="lineno">  134</span>&#160;</div><div class="line"><a name="l00135"></a><span class="lineno">  135</span>&#160;    _ps.segment(i1, 3) = -p_f;</div><div class="line"><a name="l00136"></a><span class="lineno">  136</span>&#160;    _vs.segment(i1, 3) = (1.0f - trust) * v0 + trust * (-dp_f);</div><div class="line"><a name="l00137"></a><span class="lineno">  137</span>&#160;    pzs(i) = (1.0f - trust) * (p0(2) + p_f(2));</div><div class="line"><a name="l00138"></a><span class="lineno">  138</span>&#160;  }</div><div class="line"><a name="l00139"></a><span class="lineno">  139</span>&#160;</div><div class="line"><a name="l00140"></a><span class="lineno">  140</span>&#160;</div><div class="line"><a name="l00141"></a><span class="lineno">  141</span>&#160;  Eigen::Matrix&lt;T, 28, 1&gt; y;</div><div class="line"><a name="l00142"></a><span class="lineno">  142</span>&#160;  y &lt;&lt; _ps, _vs, pzs;</div><div class="line"><a name="l00143"></a><span class="lineno">  143</span>&#160;  _xhat = _A * _xhat + _B * a;</div><div class="line"><a name="l00144"></a><span class="lineno">  144</span>&#160;  Eigen::Matrix&lt;T, 18, 18&gt; At = _A.transpose();</div><div class="line"><a name="l00145"></a><span class="lineno">  145</span>&#160;  Eigen::Matrix&lt;T, 18, 18&gt; Pm = _A * _P * At + Q;</div><div class="line"><a name="l00146"></a><span class="lineno">  146</span>&#160;  Eigen::Matrix&lt;T, 18, 28&gt; Ct = _C.transpose();</div><div class="line"><a name="l00147"></a><span class="lineno">  147</span>&#160;  Eigen::Matrix&lt;T, 28, 1&gt; yModel = _C * _xhat;</div><div class="line"><a name="l00148"></a><span class="lineno">  148</span>&#160;  Eigen::Matrix&lt;T, 28, 1&gt; ey = y - yModel;</div><div class="line"><a name="l00149"></a><span class="lineno">  149</span>&#160;  Eigen::Matrix&lt;T, 28, 28&gt; S = _C * Pm * Ct + R;</div><div class="line"><a name="l00150"></a><span class="lineno">  150</span>&#160;</div><div class="line"><a name="l00151"></a><span class="lineno">  151</span>&#160;  <span class="comment">// todo compute LU only once</span></div><div class="line"><a name="l00152"></a><span class="lineno">  152</span>&#160;  Eigen::Matrix&lt;T, 28, 1&gt; S_ey = S.lu().solve(ey);</div><div class="line"><a name="l00153"></a><span class="lineno">  153</span>&#160;  _xhat += Pm * Ct * S_ey;</div><div class="line"><a name="l00154"></a><span class="lineno">  154</span>&#160;</div><div class="line"><a name="l00155"></a><span class="lineno">  155</span>&#160;  Eigen::Matrix&lt;T, 28, 18&gt; S_C = S.lu().solve(_C);</div><div class="line"><a name="l00156"></a><span class="lineno">  156</span>&#160;  _P = (Eigen::Matrix&lt;T, 18, 18&gt;::Identity() - Pm * Ct * S_C) * Pm;</div><div class="line"><a name="l00157"></a><span class="lineno">  157</span>&#160;</div><div class="line"><a name="l00158"></a><span class="lineno">  158</span>&#160;  Eigen::Matrix&lt;T, 18, 18&gt; Pt = _P.transpose();</div><div class="line"><a name="l00159"></a><span class="lineno">  159</span>&#160;  _P = (_P + Pt) / T(2);</div><div class="line"><a name="l00160"></a><span class="lineno">  160</span>&#160;</div><div class="line"><a name="l00161"></a><span class="lineno">  161</span>&#160;  <span class="keywordflow">if</span> (_P.block(0, 0, 2, 2).determinant() &gt; T(0.000001)) {</div><div class="line"><a name="l00162"></a><span class="lineno">  162</span>&#160;    _P.block(0, 2, 2, 16).setZero();</div><div class="line"><a name="l00163"></a><span class="lineno">  163</span>&#160;    _P.block(2, 0, 16, 2).setZero();</div><div class="line"><a name="l00164"></a><span class="lineno">  164</span>&#160;    _P.block(0, 0, 2, 2) /= T(10);</div><div class="line"><a name="l00165"></a><span class="lineno">  165</span>&#160;  }</div><div class="line"><a name="l00166"></a><span class="lineno">  166</span>&#160;</div><div class="line"><a name="l00167"></a><span class="lineno">  167</span>&#160;  this-&gt;_stateEstimatorData.result-&gt;position = _xhat.block(0, 0, 3, 1);</div><div class="line"><a name="l00168"></a><span class="lineno">  168</span>&#160;  this-&gt;_stateEstimatorData.result-&gt;vWorld = _xhat.block(3, 0, 3, 1);</div><div class="line"><a name="l00169"></a><span class="lineno">  169</span>&#160;  this-&gt;_stateEstimatorData.result-&gt;vBody =</div><div class="line"><a name="l00170"></a><span class="lineno">  170</span>&#160;      this-&gt;_stateEstimatorData.result-&gt;rBody *</div><div class="line"><a name="l00171"></a><span class="lineno">  171</span>&#160;      this-&gt;_stateEstimatorData.result-&gt;vWorld;</div><div class="line"><a name="l00172"></a><span class="lineno">  172</span>&#160;}</div><div class="line"><a name="l00173"></a><span class="lineno">  173</span>&#160;</div><div class="line"><a name="l00174"></a><span class="lineno">  174</span>&#160;<span class="keyword">template</span> <span class="keyword">class </span><a class="code" href="../../d1/d83/class_linear_k_f_position_velocity_estimator.html">LinearKFPositionVelocityEstimator&lt;float&gt;</a>;</div><div class="line"><a name="l00175"></a><span class="lineno">  175</span>&#160;<span class="keyword">template</span> <span class="keyword">class </span><a class="code" href="../../d1/d83/class_linear_k_f_position_velocity_estimator.html">LinearKFPositionVelocityEstimator&lt;double&gt;</a>;</div><div class="line"><a name="l00176"></a><span class="lineno">  176</span>&#160;</div><div class="line"><a name="l00177"></a><span class="lineno">  177</span>&#160;</div><div class="line"><a name="l00178"></a><span class="lineno">  178</span>&#160;</div><div class="line"><a name="l00179"></a><span class="lineno">  179</span>&#160;<span class="keyword">template</span> &lt;<span class="keyword">typename</span> T&gt;</div><div class="line"><a name="l00180"></a><span class="lineno"><a class="line" href="../../d1/d10/class_cheater_position_velocity_estimator.html#a2f96fc0e623e2b3305c4330f805db781">  180</a></span>&#160;<span class="keywordtype">void</span> <a class="code" href="../../d1/d10/class_cheater_position_velocity_estimator.html#a2f96fc0e623e2b3305c4330f805db781">CheaterPositionVelocityEstimator&lt;T&gt;::run</a>() {</div><div class="line"><a name="l00181"></a><span class="lineno">  181</span>&#160;  this-&gt;_stateEstimatorData.result-&gt;position = this-&gt;_stateEstimatorData.cheaterState-&gt;position.template cast&lt;T&gt;();</div><div class="line"><a name="l00182"></a><span class="lineno">  182</span>&#160;  this-&gt;_stateEstimatorData.result-&gt;vWorld =</div><div class="line"><a name="l00183"></a><span class="lineno">  183</span>&#160;      this-&gt;_stateEstimatorData.result-&gt;rBody.transpose().template cast&lt;T&gt;() * this-&gt;_stateEstimatorData.cheaterState-&gt;vBody.template cast&lt;T&gt;();</div><div class="line"><a name="l00184"></a><span class="lineno">  184</span>&#160;  this-&gt;_stateEstimatorData.result-&gt;vBody = this-&gt;_stateEstimatorData.cheaterState-&gt;vBody.template cast&lt;T&gt;();</div><div class="line"><a name="l00185"></a><span class="lineno">  185</span>&#160;}</div><div class="line"><a name="l00186"></a><span class="lineno">  186</span>&#160;</div><div class="line"><a name="l00187"></a><span class="lineno">  187</span>&#160;<span class="keyword">template</span> <span class="keyword">class </span><a class="code" href="../../d1/d10/class_cheater_position_velocity_estimator.html">CheaterPositionVelocityEstimator&lt;float&gt;</a>;</div><div class="line"><a name="l00188"></a><span class="lineno">  188</span>&#160;<span class="keyword">template</span> <span class="keyword">class </span><a class="code" href="../../d1/d10/class_cheater_position_velocity_estimator.html">CheaterPositionVelocityEstimator&lt;double&gt;</a>;</div><div class="ttc" id="class_linear_k_f_position_velocity_estimator_html_a5a71e5a86165a39dda4c6ad81304299a"><div class="ttname"><a href="../../d1/d83/class_linear_k_f_position_velocity_estimator.html#a5a71e5a86165a39dda4c6ad81304299a">LinearKFPositionVelocityEstimator::run</a></div><div class="ttdeci">virtual void run()</div><div class="ttdef"><b>Definition:</b> <a href="../../d6/d39/_position_velocity_estimator_8cpp_source.html#l00054">PositionVelocityEstimator.cpp:54</a></div></div>
<div class="ttc" id="class_quadruped_html"><div class="ttname"><a href="../../dc/d66/class_quadruped.html">Quadruped</a></div><div class="ttdef"><b>Definition:</b> <a href="../../d3/dc7/_quadruped_8h_source.html#l00056">Quadruped.h:56</a></div></div>
<div class="ttc" id="cpp_types_8h_html_aa8cb424e643d476ea485238dad7c3e18"><div class="ttname"><a href="../../d9/d8e/cpp_types_8h.html#aa8cb424e643d476ea485238dad7c3e18">Mat3</a></div><div class="ttdeci">typename Eigen::Matrix&lt; T, 3, 3 &gt; Mat3</div><div class="ttdef"><b>Definition:</b> <a href="../../d9/d8e/cpp_types_8h_source.html#l00054">cppTypes.h:54</a></div></div>
<div class="ttc" id="cpp_types_8h_html_a6f07728c866b15ff0676a9b2ebfd2ba6"><div class="ttname"><a href="../../d9/d8e/cpp_types_8h.html#a6f07728c866b15ff0676a9b2ebfd2ba6">Vec3</a></div><div class="ttdeci">typename Eigen::Matrix&lt; T, 3, 1 &gt; Vec3</div><div class="ttdef"><b>Definition:</b> <a href="../../d9/d8e/cpp_types_8h_source.html#l00026">cppTypes.h:26</a></div></div>
<div class="ttc" id="class_linear_k_f_position_velocity_estimator_html_a6fcb890559e303e4c8e13cef4dd6c4d9"><div class="ttname"><a href="../../d1/d83/class_linear_k_f_position_velocity_estimator.html#a6fcb890559e303e4c8e13cef4dd6c4d9">LinearKFPositionVelocityEstimator::LinearKFPositionVelocityEstimator</a></div><div class="ttdeci">EIGEN_MAKE_ALIGNED_OPERATOR_NEW LinearKFPositionVelocityEstimator()</div><div class="ttdef"><b>Definition:</b> <a href="../../d6/d39/_position_velocity_estimator_8cpp_source.html#l00051">PositionVelocityEstimator.cpp:51</a></div></div>
<div class="ttc" id="class_quadruped_html_a594bd8c71ee8f6c388501b4c463d26b2"><div class="ttname"><a href="../../dc/d66/class_quadruped.html#a594bd8c71ee8f6c388501b4c463d26b2">Quadruped::getHipLocation</a></div><div class="ttdeci">Vec3&lt; T &gt; getHipLocation(int leg)</div><div class="ttdef"><b>Definition:</b> <a href="../../d3/dc7/_quadruped_8h_source.html#l00083">Quadruped.h:83</a></div></div>
<div class="ttc" id="class_cheater_position_velocity_estimator_html_a2f96fc0e623e2b3305c4330f805db781"><div class="ttname"><a href="../../d1/d10/class_cheater_position_velocity_estimator.html#a2f96fc0e623e2b3305c4330f805db781">CheaterPositionVelocityEstimator::run</a></div><div class="ttdeci">virtual void run()</div><div class="ttdef"><b>Definition:</b> <a href="../../d6/d39/_position_velocity_estimator_8cpp_source.html#l00180">PositionVelocityEstimator.cpp:180</a></div></div>
<div class="ttc" id="class_linear_k_f_position_velocity_estimator_html_aa6cde24b1d9be72b01cfae1534e7580f"><div class="ttname"><a href="../../d1/d83/class_linear_k_f_position_velocity_estimator.html#aa6cde24b1d9be72b01cfae1534e7580f">LinearKFPositionVelocityEstimator::setup</a></div><div class="ttdeci">virtual void setup()</div><div class="ttdef"><b>Definition:</b> <a href="../../d6/d39/_position_velocity_estimator_8cpp_source.html#l00004">PositionVelocityEstimator.cpp:4</a></div></div>
<div class="ttc" id="cpp_types_8h_html_a738072d0d6a7a632be68f6261501826b"><div class="ttname"><a href="../../d9/d8e/cpp_types_8h.html#a738072d0d6a7a632be68f6261501826b">Vec4</a></div><div class="ttdeci">typename Eigen::Matrix&lt; T, 4, 1 &gt; Vec4</div><div class="ttdef"><b>Definition:</b> <a href="../../d9/d8e/cpp_types_8h_source.html#l00030">cppTypes.h:30</a></div></div>
<div class="ttc" id="_position_velocity_estimator_8h_html"><div class="ttname"><a href="../../df/ddd/_position_velocity_estimator_8h.html">PositionVelocityEstimator.h</a></div><div class="ttdoc">All State Estimation Algorithms. </div></div>
<div class="ttc" id="class_cheater_position_velocity_estimator_html"><div class="ttname"><a href="../../d1/d10/class_cheater_position_velocity_estimator.html">CheaterPositionVelocityEstimator</a></div><div class="ttdef"><b>Definition:</b> <a href="../../df/ddd/_position_velocity_estimator_8h_source.html#l00036">PositionVelocityEstimator.h:36</a></div></div>
<div class="ttc" id="class_linear_k_f_position_velocity_estimator_html"><div class="ttname"><a href="../../d1/d83/class_linear_k_f_position_velocity_estimator.html">LinearKFPositionVelocityEstimator</a></div><div class="ttdef"><b>Definition:</b> <a href="../../df/ddd/_position_velocity_estimator_8h_source.html#l00016">PositionVelocityEstimator.h:16</a></div></div>
<div class="ttc" id="test__casadi_8cpp_html_ae20d7fba59865a21504b65cdb44cbfe5"><div class="ttname"><a href="../../dc/dd7/test__casadi_8cpp.html#ae20d7fba59865a21504b65cdb44cbfe5">f</a></div><div class="ttdeci">MX f(const MX &amp;x, const MX &amp;u)</div><div class="ttdef"><b>Definition:</b> <a href="../../dc/dd7/test__casadi_8cpp_source.html#l00202">test_casadi.cpp:202</a></div></div>
</div><!-- fragment --></div><!-- contents -->
</div><!-- doc-content -->
<!-- start footer part -->
<div id="nav-path" class="navpath"><!-- id is needed for treeview function! -->
  <ul>
    <li class="navelem"><a class="el" href="../../dir_43e0a1f539e00dcfa1a6bc4d4fee4fc2.html">home</a></li><li class="navelem"><a class="el" href="../../dir_61bfb0b3cdda81b1b0355ba34eb3b1eb.html">dhkim</a></li><li class="navelem"><a class="el" href="../../dir_adee5b101e079090017bb4e91c628ead.html">Public_Repository</a></li><li class="navelem"><a class="el" href="../../dir_7fc07a7b97001e7b1d18e11da761e2de.html">Cheetah-Software</a></li><li class="navelem"><a class="el" href="../../dir_860379c26524a894b3cf97b5b1ba5bdb.html">common</a></li><li class="navelem"><a class="el" href="../../dir_054bbb67b14bc4d9ad4b8f9fd2c17d22.html">src</a></li><li class="navelem"><a class="el" href="../../dir_96a731a19886ddb7526afb72ff6db908.html">Controllers</a></li><li class="navelem"><a class="el" href="../../d6/d39/_position_velocity_estimator_8cpp.html">PositionVelocityEstimator.cpp</a></li>
    <li class="footer">Generated by
    <a href="http://www.doxygen.org/index.html">
    <img class="footer" src="../../doxygen.png" alt="doxygen"/></a> 1.8.11 </li>
  </ul>
</div>
</body>
</html>
